//
//  UserAccount.m
//  weibo110
//
//  Created by 臧松 on 15/12/27.
//  Copyright © 2015年 臧松. All rights reserved.
//

#import "UserAccount.h"

@implementation UserAccount

+(instancetype)accountWithDict:(NSDictionary *)dict{
    return [[self alloc]initWithDict:dict];
}
-(instancetype)initWithDict:(NSDictionary *)dict{
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict];
        
    }
    return self;
}
// 过滤没有的键值对
-(void)setValue:(id)value forUndefinedKey:(NSString *)key{}

-(NSString *)description{
    
    NSArray * keys = @[@"access_token",@"expires_in",@"uid",@"avatar_large",@"screen_name",@"expieresDate"];
    
    return [self dictionaryWithValuesForKeys:keys].description;
}

//  MARK: - 归档保存用户信息
// 归档
-(void)encodeWithCoder:(NSCoder *)aCoder{
    
    [aCoder encodeObject:self.access_token forKey:@"access_token"];
    [aCoder encodeObject:self.expieresDate forKey:@"expieresDate"];
    [aCoder encodeObject:self.uid forKey:@"uid"];
    [aCoder encodeObject:self.screen_name forKey:@"screen_name"];
    [aCoder encodeObject:self.avatar_large forKey:@"avatar_large"];
}
// 解档
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super init]) {
        self.access_token = [aDecoder decodeObjectForKey:@"access_token"];
        self.expieresDate = [aDecoder decodeObjectForKey:@"expieresDate"];
        self.uid = [aDecoder decodeObjectForKey:@"uid"];
        self.screen_name = [aDecoder decodeObjectForKey:@"screen_name"];
        self.avatar_large = [aDecoder decodeObjectForKey:@"avatar_large"];
    }
    return self;
}
@end
